import router from '@/router'
//添加一个请求拦截器
axios.interceptors.request.use(function (config) {
    let token = sessionStorage.getItem('token');
    config.headers.common['Authorization'] = token;
    return config;
}, function (error) {
    // Do something with request error
    console.error("error: ", error);
    return Promise.reject(error);
});
// 响应拦截器
axios.interceptors.response.use(res => {
    if (res.data.statusCode === 401) {
        sessionStorage.setItem('token', '');
        router.replace('/login');
        return res;
    } else {
        return res;
    }
}, function (err) {
    //错误处理
    console.error(err);
});